from dlgo.agent.naive import RandomBot
from dlgo import gotypes
from dlgo import goboard_slow
from dlgo.utils import print_move, print_board
import time

def main():
    # 规定棋盘边长为9个棋子
    board_size = 9
    # 新建一个游戏
    game = goboard_slow.GameState.new_game(board_size)
    bots = {
        gotypes.Player.black: RandomBot(),
        gotypes.Player.white: RandomBot()
    }
    while not game.is_over():
        # 休息0.3秒
        time.sleep(0.3)
        # 清空屏幕
        print(chr(27) + '[2J')
        # 打印棋盘
        print_board(game.board)
        # 下棋方选择一个行为
        bot_move = bots[game.next_player].select_move(game)
        # 打印行为
        print_move(game.next_player, bot_move)
        # 完成行为
        game = game.apply_move(bot_move)



if __name__ == '__main__':
    main()